import datetime

from google.appengine.api import users
from google.appengine.api import datastore
from google.appengine.api import mail

import tvdb
import tvweb

class RPCAdminMethods:
    
    def ResetSerie(self, *args):
        val = False
        try:
            cals = tvdb.restore_calendar_by_serie(args[0])
            if cals.count() > 0:
                for cal in cals:
                    cal.delete()
            val = tvweb.obtain_episodes_list(args[0])
        except Exception, reason:
            return str(reason)
        return args[0] if val else ''

    def SendMessage(self, *args):
        users = tvdb.obtain_actual_users()
        mailFrom = "pytv.series@gmail.com"
        subject = "PyTv: News"
        for user in users:
            mailTo = user + "@gmail.com"
            body = args[0]
            mail.send_mail(mailFrom, mailTo, subject, body)
